package com.comleader.operator.service;

import static com.comleader.operator.pojo.entity.table.IovCardTableDef.IOV_CARD;
import static com.mybatisflex.core.query.QueryMethods.distinct;
import static com.mybatisflex.core.query.QueryMethods.select;

import java.util.List;

import org.springframework.stereotype.Service;

import com.comleader.operator.mapper.IovCardMapper;
import com.comleader.operator.pojo.entity.IovCardEntity;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 车联网卡表 服务层实现。
 *
 * @author 连新景
 * @since 1.0
 */
@Service
public class IovCardService extends CustomService<IovCardMapper, IovCardEntity> {

    /**
     * @Description 查询一证十号的数据（同一机主证件，开通10张以上车联网卡的数据）
     * @Auhtor 连新景
     * @Date 2024/08/12 15:53
     * @return java.util.List<com.comleader.operator.pojo.entity.IovCardEntity>
     */
    public List<IovCardEntity> listOneCardTenNumbers() {
        QueryWrapper queryWrapper = QueryWrapper.create().where(IOV_CARD.OWNER_ID_NUMBER.in(select(IOV_CARD.OWNER_ID_NUMBER).from(IOV_CARD)
            .groupBy(IOV_CARD.OWNER_ID_NUMBER).having(QueryMethods.count(distinct(IOV_CARD.USER_NUMBER)).gt(10))));
        return list(queryWrapper);
    }
}